package easy;

public class Day11 {
    public static void main(String[] args) {
        System.out.println(countAndSay(10));
    }


    public static String countAndSay(int n) {
        // 递归终止条件
        if (n == 1) {
            return "1";
        }
        // 用来生成本次的字符串
        StringBuilder res = new StringBuilder();
        // 拿到上一层的字符串
        String str = countAndSay(n - 1);
        System.out.println(str);
        int start = 0;
        for (int i = 0; i < str.length() + 1; i++) {
            if (i == str.length()) {
                res.append(i - start).append(str.charAt(start));
                continue;
            }
            if (str.charAt(i) != str.charAt(start)) {
                res.append(i - start).append(str.charAt(start));
                start = i;
            }
        }

        return res.toString();

    }
}
